/*
 * CodeSaveCommand.java
 *
 * Created on 2006년 3월 29일 (수), 오후 4:11
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.qbooks.member;

import java.util.*;




import javax.servlet.*;
import javax.servlet.http.*;

import org.json.simple.JSONObject;

import com.zll.framework.model.HashBox;
import com.zll.framework.model.HashList;
import com.zll.framework.servlet.Command;
import com.qbooks.common.CommonDAO;
import com.qbooks.common.CommonUtil;





/**
 *
 * @author eastar
 */
public class MemberRegistCommand implements Command
{

    public String execute(HttpServletRequest  request, HttpServletResponse response)
    throws Exception
    {
    	JSONObject json = new JSONObject();

		HashBox box = new HashBox(request);

		MemberDAO dao 		= new MemberDAO();

		
		HashList list = dao.selectMemberList(box.getParam());

		if (list.size() == 0) 
		{
			box.put("job_type", "C");
			
			dao.saveMember(box.getParam());

			json.put("result", true);
			json.put("message", "회원가입을 성공했습니다.");
			

		} else {
			json.put("result", false);
			if ("1".equals(list.get("status",0))) {
				json.put("message", "이미 회원가입되어 있습니다.");
			} else if ("9".equals(list.get("status",0))) {
				json.put("message", "탈퇴한 회원입니다.");
			} else {
				json.put("message", "회원가입에 실패하였습니다.");
			}
		}

		request.setAttribute("jsonData", json.toString());


    	return "/common/json_view.jsp";
    }
}
